# Makefile GnomePulseAppletInterface
#
# Copyright (C) 2009  Harry Karvonen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Author: Harry Karvonen <harry.karvonen@gmail.com>
#

DESTDIR =
PREFIX = /usr
#LIBDIR =
#PYTHON_VERSION =
#LIBDIR = $(if $(wildcard $(DESTDIR)$(PREFIX)/lib64),$(PREFIX)/lib64,$(PREFIX)/lib)
LIBDIR = $(if $(findstring $(shell uname -m),x86_64),$(PREFIX)/lib64,$(PREFIX)/lib)
PYTHON_VERSION = $(shell python -c 'import sys; print "." . join (["%s" % (a) for a in sys.version_info[:2]])')

PYTHON_PACKAGES = site-packages
#
# In ubuntu 9.04
#PYTHON_PACKAGES = dist-packages

USE_SETUPTOOL = 0

print-%:
	@echo '$(@:print-%=%) = `$($(@:print-%=%))´'



# Default target
# make
all: $(if $(findstring $(USE_SETUPTOOL),1),dist-use-setuptool,dist-no-setuptool)

# Install target
# make install
install: $(if $(findstring $(USE_SETUPTOOL),1),install-use-setuptool,install-no-setuptool)

install-use-setuptool: dist
	install -D dist/*.egg \
          $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES)/
	echo `basename dist/*.egg` > \
          $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES)/GnomePulseAppletInterface.pth

install-no-setuptool:
	mkdir -p $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES)/
	cp -r $(shell pwd)/GnomePulseAppletInterface $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES)/
	echo "GnomePulseAppletInterface" > \
          $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES)/GnomePulseAppletInterface.pth

dist-use-setuptool:
	python setup.py bdist_egg

dist-no-setuptool:
	@echo "FIXME: compile python sources"

install-devel:
	$(if $(findstring $(USE_SETUPTOOL),1),\
          python setup.py develop -d \
            $(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES),\
          echo $(shell pwd) > \
            $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES)/GnomePulseAppletInterface.pth \
        )

uninstall:
	$(RM) -r $(DESTDIR)$(LIBDIR)/python$(PYTHON_VERSION)/$(PYTHON_PACKAGES)/GnomePulseAppletInterface*

clean:
	$(RM) -r dist/ build/ GnomePulseAppletInterface.egg-info
